js.datamanage_class = {}

/**
*	数据库表格管理
*/
js.datamanage_class.table = function(can){
	var me = this;
	js.baseclass.call(this, can); //这个必须要写，继承默认的方法
	
	this.onPage = function(){
		$('#table_list'+this.rand+'').change(function(){
			me.changetable(this);
		});
		this.table = new js.table.create({
			url:'?m=datamanage&a=data',autoLoad:false,fanye:true,autoheight:true,resizeh:22,height:300,
			view:'table_view'+this.rand+'',
			columns:[{
				text:'字段',dataIndex:'fields'
			},{
				text:'内容',dataIndex:'cont'
			}],
			onloadbefore:function(d){
				if(d.fieldsarr)me.showcolumns(d.fieldsarr);
			}
		});
	}
	
	this.dbmanage = function(){
		window.open('?m=dbmanage');
	}
	
	this.showcolumns = function(da){
		var ds=[],d,d1,i,len=da.length,fid,df=[];
		for(i=0;i<len;i++){
			d1= da[i];fid = d1.fields;
			d = {text:fid,dataIndex:fid}
			if(d1.name)d.text+='('+d1.name+')';
			if(d1.dbtype.indexOf('int')>=0)d.sortable=true;
			ds.push(d);
			df.push({name:d.text,value:d.dataIndex});
		}
		this.table.setColumns(ds);
		var ov = get('fields_select'+this.rand+'');
		ov.length = 1;
		js.setselectdata(ov, df, 'value');
	}
	
	this.search = function(){
		var fid = get('fields_select'+this.rand+'').value;
		this.table.setparams({
			'fshow' : '',
			'fields_select': fid, 
			'fields_like'  : get('fields_like'+this.rand+'').value,
			'fields_keyword':jm.base64encode(get('fields_keyword'+this.rand+'').value)
		}, true);
	}
	
	this.changetable = function(o){
		var val = o.value;
		if(!val)return;
		this.table.sort = '';
		this.table.dir  = '';
		var fshow = (this.nowtable == val) ? '' : 'show';
		this.table.setparams({table:val,fshow:fshow,fields_select:''}, true);
		this.nowtable = val;
	}
}